package cz.cvut.testRMI;

import java.io.Serializable;


public class Container implements Serializable {
	public static final long serialVersionUID = 1L;
	
	protected volatile String jmeno;
	protected volatile String prijmeni; 
	
	private class Adresa implements Serializable {
		public static final long serialVersionUID = 1L;
		
		protected String ulice;
		protected String mesto;
		protected String zeme;
		protected int cp;
		
		Adresa(String ulice, int cp, String mesto, String zeme) {
			this.ulice = ulice;
			this.cp = cp;
			this.mesto = mesto;
			this.zeme = zeme;
		}
		
		public String toString() {
			return ulice + " " + cp + ", " + mesto + ", " + zeme;
		}
	}
	
	private Adresa[] adresa;
	
	Container(String jmeno, String prijmeni, String ulice, int cp, String mesto, String zeme) {
		this.jmeno = jmeno;
		this.prijmeni = prijmeni;
		this.adresa = new Adresa[3];
		for (int i=0; i<3; i++) {
			this.adresa[i] = new Adresa(ulice, cp+i, mesto, zeme);
		}
	}
	
	Container(Container old) {
		this.jmeno = old.jmeno;
		this.prijmeni = old.prijmeni;
		this.adresa = new Adresa[3];
		for (int i=0; i<old.adresa.length; i++) {
			this.adresa[i] = new Adresa(old.adresa[i].ulice, old.adresa[i].cp, old.adresa[i].mesto, old.adresa[i].zeme);
		}
	}
	
	public String toString() {
		String adresy = "";
		for (int i=0; i<adresa.length; i++) {
			if (i!=0) {
				adresy += " | " + adresa[i];
			} else {
				adresy += adresa[i];
			}
		}
		return jmeno + " " + prijmeni + ", (" + adresy + ")";
	}
	
	public void change() {
		this.jmeno = this.jmeno + "123";
		for (int i=0; i<adresa.length; i++) this.adresa[i].zeme = "Zimbabwe";
	}
}
